<template>
  <div id="">
    <headerbox :headerTitle="'通讯录'" :headerRightTxt="'确定'" @headerRightEvent="headerRightEvent"></headerbox>
    <ul class="formList">
      <li v-for="(contact,index) in addressbookList" :key="contact.id"
      @click="sendMsg(index)">{{contact.displayName}}</li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "",
  props: ['addressbookList'],
  data: () => ({

  }),
  methods: {
    headerRightEvent() {
      this.$emit('addressbookEvent');
    },
    // 发送短信
    sendMsg(index) {
      let self = this;
      let contact = self.addressbookList[index];
      let msg = plus.messaging.createMessage(plus.messaging.TYPE_SMS);
    	msg.to = [contact.phoneNumbers[0].value];
    	msg.body = '这里是发送短信的内容部分';
      plus.messaging.sendMessage( msg,function(){
				//success
        // console.log('send messge success');
        self.toast('短信发送成功');
        self.$emit('addressbookEvent'); //返回父组件，关闭弹窗
			},function(){
				//error
        // console.log('send messge error');
        self.toast('发送失败');
        self.$emit('addressbookEvent'); //返回父组件，关闭弹窗
			} );
    }
  },
  mounted() {
    //do something after mounting vue instance
    console.log(this.addressbookList);
  }
}
</script>
<style lang="scss" scoped>
</style>
